import 'package:decimal/decimal.dart';

import 'StorageUtil.dart';

class MoneyUtil{
  static String getMoneyStr(var money){
     String str="";

     var currency=StorageUtil.getCurrency();
     currency ??= "0";
     var currencyRate=StorageUtil.getCurrencyRate();
     currencyRate??="1";
     //未设置时，默认1返回
     if(currency=="0"){
        str="￥$money";
     }else if(currency=="1"){
       str= (Decimal.parse(money)/Decimal.parse(currencyRate)).toStringAsFixed(2);
       str="\$$str";
     }else if(currency=="2"){
        str= (Decimal.parse(money)/Decimal.parse(currencyRate)).toStringAsFixed(2);
        str="€$str";
     }
     if(str.endsWith(".00")){
       str=str.substring(0,str.length-3);
     }

     return str;
  }
  static String mutileMoney(var m1,var m2){
    return (Decimal.parse(m1)*Decimal.parse(m2)).toStringAsFixed(2);
  }

  static String addMoney(var m1,var m2){
    return (Decimal.parse(m1)+Decimal.parse(m2)).toStringAsFixed(2);
  }
  static String minusMoney(var m1,var m2){
    return (Decimal.parse(m1)-Decimal.parse(m2)).toStringAsFixed(2);
  }
  static String countDeposit(var m1,var m2){
    return (Decimal.parse(m1)*Decimal.parse(m2)/Decimal.parse("100")).toStringAsFixed(2);
  }

  static String countDiscount(var m1,var m2){
    return (Decimal.parse(m1)-Decimal.parse(m1)*Decimal.parse(m2)/Decimal.parse("100")).toStringAsFixed(2);
  }

  static bool compairDiscount(var m1,var m2){
   var value1= Decimal.parse(m1);
   var value2=Decimal.parse(m2);
   return value1>value2;
  }
}